package alogrithm;

import java.util.HashSet;
import java.util.Set;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/10/18 13:30
 */
public class MLS {

    public int MLS(int[] arr) {
        // write code here
        if (arr.length == 0) {
            return 0;
        }
        Set<Integer> set = new HashSet<>();
        for (int i : arr) {
            set.add(i);
        }
        int res = 0;
        for (int j : arr) {
            if (set.contains(j - 1)) {
                continue;
            }
            int start = j;
            while (set.contains(start + 1)) {
                start++;
            }
            res = Math.max(res, start - j + 1);
        }

        return res;
    }
}
